import sysConfig from "@/config";
// 登陆后菜单转换
export function filterAsyncRouter(routerMap) {
	const accessedRouters = []
	routerMap.forEach(item => {
		item.meta = {
			icon: item.icon,
			title: item.title,
			type: item.type,
			hidden: item.hidden
		};
		// item.meta = item.meta && item.meta[0] ? item.meta[0] : item.meta ? item.meta : {
		// 	icon: item.icon,
		// 	title: item.title,
		// 	type: item.type,
		// 	hidden: item.hidden
		// };
		//处理外部链接特殊路由
		if (item.meta.type == 'iframe') {
			item.meta.url = item.path;
			item.path = `/i/${item.name}`;
		}
		//MAP转路由对象
		var route = {
			id: item.id,
			path: item.path,
			name: item.name,
			code: item.code,
			meta: item.meta,
			redirect: item.redirect,
			children: item.children ? filterAsyncRouter(item.children) : null,
			component: item.component
		}
		accessedRouters.push(route)
	})
	return accessedRouters
}

// 菜单设置页菜单转换
export function filterAsyncRouter1(routerMap) {
	const accessedRouters = []
	routerMap.forEach(item => {
		item.meta = {
			icon: item.icon,
			title: item.title,
			type: item.type,
			hidden: item.hidden
		};
		// item.meta = item.meta && item.meta[0] ? item.meta[0] : item.meta ? item.meta : {
		// 	icon: item.icon,
		// 	title: item.title,
		// 	type: item.type,
		// 	hidden: item.hidden
		// };
		//处理外部链接特殊路由
		if (item.meta.type == 'iframe') {
			item.meta.url = item.path;
			item.path = `/i/${item.name}`;
		}
		//MAP转路由对象
		var route = {
			id: item.id,
			path: item.path,
			name: item.name,
			code: item.code,
			meta: item.meta,
			sort: item.sort,
			redirect: item.redirect,
			children: item.children ? filterAsyncRouter(item.children) : null,
			component: item.component
		}
		accessedRouters.push(route)
	})
	return accessedRouters
}

// 图片链接加上地址
export function filterAsyncImgs(data, path, url) {
	const data2 = []
	data.forEach(item => {
		let obj = {}
		obj[path] = item
		obj[url] = sysConfig.IMG_URL+item
		data2.push(obj)
	})
	return data2
}
